package cn.cqie.attendance.teacher.controller;

import cn.cqie.attendance.common.util.Page;
import cn.cqie.attendance.common.util.PageBean;
import cn.cqie.attendance.teacher.pojo.TeacherLeave;
import cn.cqie.attendance.teacher.pojo.TeacherLeaveLog;
import cn.cqie.attendance.teacher.service.TeacherLeaveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;

/**
 * @author wqh
 * @date 2021/6/21 17:14
 */
@RestController
@Api(tags = "教师端-请假管理模块")
@RequestMapping("/teacher/leave")
public class TeacherLeaveController {

    @Autowired
    private TeacherLeaveService teacherLeaveService;


    @GetMapping("/queryLeaveByTeacherId")
    @ApiOperation("老师查看自己课程下学生的请假信息")
    public PageBean<TeacherLeave> queryLeaveByTeacherId(Date beginTime, Date endTime, Integer collegeId, Integer majorId, Integer gradeId, Integer classId, String stuNumber, String stuName, String leaveTheme, Integer leaveReason, Integer leaveStatus, Integer pageNum, Integer pageSize){
        return teacherLeaveService.queryLeaveByTeacherId(beginTime,endTime,collegeId,majorId,gradeId,classId,stuNumber,stuName,leaveTheme,leaveReason,leaveStatus,pageNum,pageSize);
    }


    @GetMapping("/queryLeaveInfoByLeaveId")
    @ApiOperation("查看该老师课程下的学生的请假详情")
    public Page queryLeaveInfoByLeaveId(@RequestParam(value = "leaveId")Integer leaveId) {
        return teacherLeaveService.queryLeaveInfoByLeaveId(leaveId);
    }


    @GetMapping("/queryLeaveLogInfoByLeaveLogId")
    @ApiOperation("学生请假信息的请假流程管理")
    public PageBean<TeacherLeaveLog> queryLeaveLogInfoByLeaveLogId(@RequestParam(value = "leaveId")Integer leaveId, Integer pageNum, Integer pageSize) {
        return teacherLeaveService.queryLeaveLogInfoByLeaveLogId(leaveId,pageNum,pageSize);
    }


    @PostMapping("/updateLeaveStatusByLeaveId")
    @ApiOperation("根据请假id审批假条（审批通过--可以批量）")
    public Page updateLeaveStatusByLeaveId(@RequestParam(value = "leaveIds")String[] leaveIds,@RequestParam(value = "headmaster")Integer headmaster) throws ParseException {
        return teacherLeaveService.updateLeaveStatusByLeaveId(leaveIds,headmaster);
    }

    @PostMapping("/updateLeaveByLeaveId")
    @ApiOperation("根据请假id审批假条（审批不通过）")
    public Page updateLeaveByLeaveId(@RequestParam(value = "leaveId")Integer leaveId, String failedDetail,String reasonDetail, Integer headmaster,Integer stuId) throws ParseException {
        return teacherLeaveService.updateLeaveByLeaveId(leaveId,failedDetail,reasonDetail,headmaster,stuId);
    }
    /*@PostMapping("/insertIntoLeaveLog")
    @ApiOperation("修改请假状态插入一条日志记录（审批不通过）")
    public Page insertIntoLeaveLog(@RequestParam(value = "leaveId")Integer leaveId,@RequestParam(value = "leaveStatus") Integer leaveStatus,@RequestParam(value = "reasonDetail") String reasonDetail,@RequestParam(value = "failedDetail") String failedDetail) throws ParseException {
        return teacherLeaveService.insertIntoLeaveLog(leaveId,leaveStatus,reasonDetail,failedDetail);
    }*/


    @ApiOperation("根据id删除一条请假信息(可以批量删除)")
    @PostMapping("/deleteLeaveByLeaveId")
    public Page deleteLeaveByLeaveId(@RequestParam(value = "leaveIds")String leaveIds,@RequestParam(value = "headmaster")Integer headmaster) {
        return teacherLeaveService.deleteLeaveByLeaveId(leaveIds,headmaster);
    }


/*    @ApiOperation("根据id删除一条请假日志信息(可以批量删除)")
    @PostMapping("/deleteLeaveLogByLeaveLogId")
    public Page deleteLeaveLogByLeaveLogId(String leaveLogIds) {
        return teacherLeaveService.deleteLeaveLogByLeaveLogId(leaveLogIds);
    }*/
}
